import { Storage } from "../store/storage";
import request from "../utils/request"
/**
 * 
 * @param {{}} params 
 * @param {VueComponent} vueObj 
 * @returns 
 */
export function fetchList(params, vueObj) {
  return request({
    url:'/order/list',
    method:'post',
    data:params
  }).then(response => {
    console.log(vueObj);
    vueObj.$data.listLoading = false;
    vueObj.$data.list = response.data.list;
    vueObj.$data.total = response.data.total;
    vueObj.$data.listQuery.pageSize = response.data.pageSize;

    Storage.orderListByStorage(vueObj.$data.list);
  });
}

/**
 * 
 * @param {{}} params 
 * @param {VueComponent} vueObj 
 * @returns 
 */
 export function fetchListBySearch(params, vueObj) {
  return request({
    url:'/order/listBySearch',
    method:'post',
    data:params
  }).then(response => {
    console.log(vueObj);
    vueObj.$data.listLoading = false;
    vueObj.$data.list = response.data.list;
    vueObj.$data.total = response.data.total;
    vueObj.$data.listQuery.pageSize = response.data.pageSize;
    Storage.orderListByStorage(vueObj.$data.list);   
  });
}

export function closeOrder(data) {
  return request({
    url:'/order/batchCloseOrder',
    method:'post',
    data:data
  })
}

export function deleteOrder(params) {
  return request({
    url:'/order/delete',
    method:'post',
    params:params
  })
}

export function deliveryOrder(data) {
  return request({
    url:'/order/update/delivery',
    method:'post',
    data:data
  });
}

/**
 * 重新铸造
 * @param {} id 
 * @param {*} component 
 * @returns 
 */
export function recast(data, component) {

  return request({
    url:'/orderDetail/recast',
    method:'post',
    data: {
      id: data.id
    }
  }).then(res => {
    console.log("res", res);
  });
}

export function updateReceiverInfo(data) {
  return request({
    url:'/order/update/receiverInfo',
    method:'post',
    data:data
  });
}

export function getOrderDetail(id, component) {
  return request({
    url:'/orderDetail/selectByOrderId',
    method:'post',
    data: {
      id: id
    }
  }).then(res => {
    res.data.forEach((element, i) => {
      component.$set(component.$data.order.orderItemList, i, element);
    });
  });
}

export function updateMoneyInfo(data) {
  return request({
    url:'/order/update/moneyInfo',
    method:'post',
    data:data
  });
}

export function updateOrderNote(params) {
  return request({
    url:'/order/update/note',
    method:'post',
    params:params
  })
}
